<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
 session_start();
 include("top.php");
?>
<table width="766" height="438" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="209" height="438" valign="top"><div align="center">
      <?php include("left.php");?>
      </div></td>
    <td width="557" align="center" valign="top" bgcolor="#FFFFFF">
      <table width="500" border="0" align="center" cellpadding="0" cellspacing="1">
           <tr>
               <td>&nbsp;</td>
          </tr>
          <tr>
              <td height="25" colspan="5" bgcolor="#FFFFFF"><div align="center">订单信息汇总</div></td>
          </tr>
                <?php
			  //session_register("total");
                          $_SESSION['total'] = "";
                          
			  if(@$_GET['qingkong']=="yes"){
			     $_SESSION['booklist']="";
				 $_SESSION['quantity']=""; ///< @remark quantity拼成了quatity,这英文水平,啧啧
			  }
			   @$arraygwc=explode("@",$_SESSION['booklist']);
			   $s=0;
			   for($i=0;$i<count($arraygwc);$i++){
			       $s+=intval($arraygwc[$i]);
			   }
			  if($s==0 ){
				   echo "<tr>";
                   echo" <td height='25' colspan='6' bgcolor='#FFFFFF' align='center'>您的购物车为空!</td>";
                   echo"</tr>";
				}
			  else{ 
			?>
                <tr>
                  <td width="100" height="25" bgcolor="#FFFFFF"><div align="center"></div></td>
                  <td width="125" height="25" bgcolor="#B0E0E6"><div align="center">图书名称</div></td>
                  <td width="52" bgcolor="#B0E0E6"><div align="center">数量</div></td>
                  <td width="64" bgcolor="#B0E0E6"><div align="center">单价</div></td>
                  <td width="66" bgcolor="#B0E0E6"><div align="center">小计</div></td>
                  <!--
                  <td width="71" bgcolor="#B0E0E6"><div align="center">操作</div></td>
                  <td width="100" bgcolor="#FFFFFF"><div align="center"></div></td>
                  <td width="125" bgcolor="#B0E0E6"><div align="center">图书名称</div></td>
                  <td width="52" bgcolor="#B0E0E6"><div align="center">数量</div></td>
                  <td width="64" bgcolor="#B0E0E6"><div align="center">单价</div></td>
                  <td width="66" bgcolor="#B0E0E6"><div align="center">小计</div></td>
                  -->
                </tr>
                <?php
			    $total=0;
			    $array=explode("@",$_SESSION['booklist']);
				$arrayquatity=explode("@",$_SESSION['quantity']);
				 while(list($name,$value)=each($_POST)){
					  for($i=0;$i<count($array)-1;$i++){
					    if(($array[$i])==$name){
						  $arrayquatity[$i]=$value;  
						}
					}
				}
			    $_SESSION['quantity']=implode("@",$arrayquatity);
				
				for($i=0;$i<count($array)-1;$i++){ 
				   $book_id=$array[$i];
				   $num=$arrayquatity[$i];
				  
				  if($book_id!=""){
				   $sql= exectue_sql_statement($conn,"select * from Book where book_id=$book_id");
				   $info=sqlsrv_fetch_array($sql);
				   $total1=$num*$info['unit_price'];
				   $total+=$total1;
				   $_SESSION["total"]=$total;
			?>
                <tr>
                  <td height="25" bgcolor="#FFFFFF"><div align="center"><image src="<?php echo $info['book_img'];?>" width="50" height="50" border="0"></div></td>
                  <td height="25" bgcolor="#FFFFFF"><div align="center"><?php echo $info['book_name'];?></div></td>
                  <td height="25" bgcolor="#FFFFFF"><div align="center"><?php echo $num;?></div></td>
                  <td height="25" bgcolor="#FFFFFF"><div align="center"><?php echo $info['unit_price'];?>元</div></td>
                  <td height="25" bgcolor="#FFFFFF"><div align="center"><?php echo $num*$info['unit_price']."元";?></div></td>
                </tr>
                <?php
			      }
				 }
			 }
		?>
              <form method="post" action="saveorder.php">
              <tr>
                  <td colspan="5" height="25" bgcolor="#FFFFFF"><div align="center">收货地址：<?php echo $_POST['address'];?></div></td>
                  <td height="25" bgcolor="#FFFFFF"><div align="center"><input type="hidden" name="address" value="<?php echo $_POST['address'];?>"></div></td>
              </tr>
              <tr>
                <td colspan="5" height="25" bgcolor="#FFFFFF"><div align="center">收货人：<?php echo $_POST['name'];?></div></td>
                <td height="25" bgcolor="#FFFFFF"><div align="center"><input type="hidden" name="receiver" value="<?php echo $_POST['name'];?>"></div></td>
              </tr>
              <tr>
                <td colspan="5" height="25" bgcolor="#FFFFFF"><div align="center">
                    联系方式：
                    <?php
                        $sql= exectue_sql_statement($conn,"select members_tel from Members where members_name='".$_SESSION['username']."'");
                        $info=sqlsrv_fetch_array($sql);
                        echo $info['members_tel'];
                    ?>
                </div></td>
              </tr>
              <tr>
                  <td colspan="5" height="25" bgcolor="#FFFFFF"><div align="center">送货方式：<?php echo $_POST['shfs'];?></div></td>
                  <td height="25" bgcolor="#FFFFFF"><div align="center"><input type="hidden" name="shfs" value="<?php echo $_POST['shfs'];?>"></div></td>
              </tr>
              <tr>
                    <td colspan="5" height="25" bgcolor="#FFFFFF"><div align="center">请扫描以下二维码完成支付：</div></td>
                    <td height="25" bgcolor="#FFFFFF"><div align="center"></div></td>
              </tr>
              <tr>
                    <td colspan="5" height="25" bgcolor="#FFFFFF"><div align="center"><image src="image/pay.png" width="50" height="50" border="0"></div></td>
                    <td height="25" bgcolor="#FFFFFF"><div align="center"></div></td>
              </tr>
              <tr>
                  <td height="22" colspan="5" bgcolor="#FFFFFF">
                      <div align="center">
                            <input type="submit" value="确认付款">
                      </div>
                  </td>
              </tr>
              </form>
        </table>
    </td>
  </tr>
</table>
<?php
 include("bottom.php");
?>